package me.zhengjie.modules.system.repository;

import me.zhengjie.modules.system.domain.UserInfo;
import me.zhengjie.modules.system.domain.UserInsuranceInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserInsuranceInfoRepository extends JpaRepository<UserInsuranceInfo, Long>, JpaSpecificationExecutor<UserInsuranceInfo> {

    @Query(value = "SELECT * FROM user_insurance_info where acceptance = ?2 and if(?1!='', policy_no=?1, 1=1)", nativeQuery = true)
    List<UserInsuranceInfo> queryList(String policyNo, String acceptance);

    @Query(value = "SELECT * FROM user_insurance_info where acceptance != 0 and if(?1!='', policy_no=?1, 1=1)", nativeQuery = true)
    List<UserInsuranceInfo> queryList(String policyNo);


    @Query(value = "SELECT * FROM user_insurance_info where id=?1 ", nativeQuery = true)
    UserInsuranceInfo queryById(Long id);

    @Modifying
    @Query(value = "update user_insurance_info set acceptance = '1' where id = ?1", nativeQuery = true)
    void acceptance(Long id);
}
